package com.springboot.demo.controller;

import com.springboot.demo.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Description：
 * @Date： Created in 2021/12/28
 * @author： jianbin.lei
 * @Auto： <a href="mailto:493168771@qq.com">jianbin.lei</a>
 */
@Api(tags = "3-游客管理")
@RestController
@RequestMapping(value = "/guest")
public class GuestController {

    // 创建线程安全的Map，模拟users信息的存储
    static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long, User>());

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除游客", notes = "根据url的id来指定删除对象",tags = "0-系统管理")
    public String deleteUser(@PathVariable Long id) {
        users.remove(id);
        return "success";
    }

    @GetMapping("/")
    @ApiOperation(value = "获取游客列表")
    public List<User> getGuestList() {
        // 还可以通过@RequestParam从页面中传递参数来进行查询条件或者翻页信息的传递
        List<User> r = new ArrayList<User>(users.values());
        return r;
    }

}
